package com.list88zhu.android.sunflower.http.impl;

import com.list88zhu.android.sunflower.http.BaseConfig;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import retrofit2.CallAdapter;
import retrofit2.Converter;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * <pre><code>
 *
 *  </code></pre>
 *
 * @author zhuyingming@qmtv.com
 * @date 2018/9/9
 */
public class DefaultConfig extends BaseConfig {

    private final long TIME_OUT_NORMAL = 3 * 1000;

    @Override
    protected HttpUrl getBaseHttpUrl() {
        HttpUrl.Builder httpUrlBuilder = new HttpUrl.Builder();
        if (configParams.isOnline) {
            httpUrlBuilder.scheme("https").host("news-at.zhihu.com");
        }else{
            httpUrlBuilder.scheme("https").host("news-at.zhihu.com");
        }
        return httpUrlBuilder.build();
    }

    @Override
    protected OkHttpClient getOkHttpClient() {
        OkHttpClient.Builder okClientBuilder = new OkHttpClient.Builder();
        okClientBuilder.connectTimeout(TIME_OUT_NORMAL, TimeUnit.MILLISECONDS);
        okClientBuilder.readTimeout(TIME_OUT_NORMAL, TimeUnit.MILLISECONDS);
        okClientBuilder.writeTimeout(TIME_OUT_NORMAL, TimeUnit.MILLISECONDS);
        okClientBuilder.retryOnConnectionFailure(true);
        // ....
        return okClientBuilder.build();
    }

    @Override
    protected List<Converter.Factory> getConverterFactories() {
        ArrayList<Converter.Factory> factories = new ArrayList<>();
        factories.add(GsonConverterFactory.create());
        return factories;
    }

    @Override
    protected List<CallAdapter.Factory> getCallAdapterFactories() {
        ArrayList<CallAdapter.Factory> factories = new ArrayList<>();
        factories.add(RxJava2CallAdapterFactory.create());
        return factories;
    }
}
